//
//  BaseNaviView.m
//  DingDongXiChe
//
//  Created by wtjr on 2018/1/3.
//  Copyright © 2018年 xieyingze. All rights reserved.
//

#import "BaseNaviView.h"
#import "AppHeader.h"

#define kNav_BackIcon         @"dd_unity_naviBack"

@interface BaseNaviView()

@end

@implementation BaseNaviView

- (instancetype)init {
    self = [super init];
    if (self) {
        [self initSubViews];
        [self autoLayoutSubViews];
    }
    return self;
}


#pragma mark - BaseMethod

- (void)initSubViews {
    [self addSubview:self.mainView];
}

- (void)autoLayoutSubViews {
    [self.mainView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.equalTo(@0);
    }];
}

#pragma mark - Interface


#pragma mark - Delegate


#pragma mark - TouchEvent
/**
 点击左侧返回按钮
 */
- (void)onNaviBack {
    if (self.clickCompleted) {
        self.clickCompleted();
    }
}

#pragma mark - Setter


#pragma mark - Getter

- (UIView *)mainView {
    if (!_mainView) {
        _mainView = [UIView new];
        _mainView.backgroundColor = kCOLOR_white;
        
        //自定义导航栏标题
        UILabel *titleLabel = [UILabel new];
        [titleLabel setLabelStyle:@"标题" textColor:KCOLOR_font_normal textFont:kFONT_big texrAlignment:NSTextAlignmentCenter];
        [_mainView addSubview:titleLabel];
        self.titleLabel = titleLabel;
        [titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.width.equalTo(@160);
            make.height.equalTo(@20);
            make.centerX.equalTo(@0);
            make.centerY.equalTo(@10);
        }];
        
        //自定义leftItem
        UIButton *navBackButton = [UIButton new];
        [navBackButton setImage:[UIImage imageNamed:kNav_BackIcon] forState:UIControlStateNormal];
        navBackButton.imageEdgeInsets = UIEdgeInsetsMake(12, 12, 12, 12);
        [navBackButton addTarget:self action:@selector(onNaviBack) forControlEvents:UIControlEventTouchUpInside];
        self.navBackButton = navBackButton;
        [_mainView addSubview:navBackButton];
        [navBackButton mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(@10);
            make.width.equalTo(@44);
            make.height.equalTo(@44);
            make.centerY.equalTo(titleLabel);
        }];
        
        //添加下划线
        UIView *lineView = [UIView new];
        lineView.backgroundColor = kCOLOR_RGBValue(0xefefef);
        self.lineView = lineView;
        [_mainView addSubview:lineView];
        [lineView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.right.bottom.equalTo(@0);
            make.height.equalTo(@0.5f);
        }];
    }
    return _mainView;
}

@end
